# coding=utf-8

import os

path = 'C:\\Users\\Administrator\\Desktop\\计算机与软件技术系'


Filelist = []
for home, dirs, files in os.walk(path):
    for filename in files:
        # 文件名列表，包含完整路径
        Filelist.append(os.path.join(home, filename))
        # # 文件名列表，只包含文件名
        # Filelist.append( filename)

for file in Filelist:
    #路径
    #找到最后一个\的位置,从0到该位置获取根路径
    root_path = file[0:int(file.rindex("\\"))]

    person = root_path[int(root_path.rindex("\\")):len(root_path)].replace('\\','',1)

    #照片名
    fileName = file[-6:]
    # print(file[-6:])

    newFileName = fileName.replace('0','',1)

    # 总数
    count = 0
    for file1 in Filelist:
        if root_path in file1:
            count+=1

    # print(file)
    dst_path = root_path+"\\"+person+str(count)+"-"+newFileName
    # print(file)
    # print(dst_path)
    os.rename(file,os.path.join(root_path,person+str(count)+"-"+newFileName))
